package com.shopping.huaju.commodity.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

//配置类 -- 用于配置 MyBatisPlus 分页插件
@Configuration
//插件作用在 dao包下
@MapperScan("com.shopping.huaju.commodity.dao")
@EnableTransactionManagement // 开启事务管理
public class MybatisPlusInterceptorConfig {
    @Bean
    public PaginationInterceptor MybatisPlusPaginationInterceptor(){
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        //设置 数据库类型
        paginationInterceptor.setDbType(DbType.MYSQL);
        //设置 超页处理，如果输入页数 超过已有页面，会显示第一页
        paginationInterceptor.setOverflow(true);
        //设置单页限制 100 条，小于 0 如 -1 不受限制
        paginationInterceptor.setLimit(100L);
        return paginationInterceptor;
    }
}
